package com.ht.medicaltreatment.activity

import android.util.TypedValue
import android.view.Gravity
import android.view.View
import android.widget.TableLayout
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.gym.baselib.base.BaseActivity
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.fragment.MultiCreateSampleFragment
import com.ht.medicaltreatment.fragment.SingleCreateSampleFragment
import kotlinx.android.synthetic.main.activity_build_sample.*

//创建样本
class BuildSampleActivity :BaseActivity(), View.OnClickListener {

    private val tabTitles = arrayListOf("单个创建","批量创建")
    private val fragments = arrayListOf<Fragment>(SingleCreateSampleFragment(),MultiCreateSampleFragment())

    override fun getLayoutId() = R.layout.activity_build_sample

    override fun isViewStup() = true

    override fun init() {
        setTitle("创建样本")
        viewPager.adapter = object : FragmentStateAdapter(this){
            override fun getItemCount() = tabTitles.size
            override fun createFragment(position: Int): Fragment {
                return fragments[position]
            }
        }
        val tableLayout = TabLayoutMediator(tabLayout,viewPager,object : TabLayoutMediator.TabConfigurationStrategy{
            override fun onConfigureTab(tab: TabLayout.Tab, position: Int) {
                val textView = TextView(this@BuildSampleActivity)
                val params = TableLayout.LayoutParams()
                params.width = TableLayout.LayoutParams.WRAP_CONTENT
                params.height = TableLayout.LayoutParams.WRAP_CONTENT
                textView.layoutParams = params
                textView.gravity = Gravity.CENTER
                textView.setText(tabTitles[position])
                textView.setTextColor(getColor(R.color.black))
                textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,15f)
                tab.setCustomView(textView)
            }
        })
        tableLayout.attach()
    }

    override fun onClick(v: View?) {
        when(v){

        }
    }
}
